package com.student.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

import com.student.dao.StudentDao;
import com.student.entity.Page;
import com.student.entity.Student;
import com.student.service.StudentService;

@Service("studentService")
public class StudentServiceImpl implements StudentService {

	@Autowired
	private StudentDao studentDao;
	
	public StudentDao getStudentDao() {
		return studentDao;
	}

	public void setStudentDao(StudentDao studentDao) {
		this.studentDao = studentDao;
	}

	@Override
	public List<Student> selStudent(Page page) {
		if (page.getCurrentPage()==null) {
			page.setCurrentPage(1);
		}
		page.setShowCount(5);
		page.setTotalResult(this.studentDao.getTotalResult());
		return this.studentDao.selStudent(page);
	}

	@Override
	public void addStudent(Student stu) {
		this.studentDao.addStudent(stu);
	}

	@Override
	public void updateStudent(Student stu) {
		this.studentDao.updateStudent(stu);
	}

	@Override
	public void delStudent(Integer id) {
		this.studentDao.delStudent(id);
	}

	@Override
	public Student selStudent(Integer id) {
		return this.studentDao.selStudent(id);
	}

	public static void main(String[] args) {
		ApplicationContext ctx=new ClassPathXmlApplicationContext("spring.xml");
		StudentService g=(StudentServiceImpl)ctx.getBean("studentService");
		Page p=new Page();
		p.setCurrentPage(1);
		List<Student> s=g.selStudent(p);
		for (Student student : s) {
			System.out.println(student.getName());
			System.out.println(student.getAddress());
			System.out.println(student.getTel());
			System.out.println(student.getBirthday());
		}
		
		
	}
}
